from django.db import models
from django.contrib import admin

class Application(models.Model):
	CompanyName = models.CharField(max_length = 60)
	SubmitDate = models.DateTimeField(
										#auto_now = True,
										#auto_now_add = True
									)
	Contact = models.CharField(max_length = 60)
	Description = models.TextField()
	IsApplied = models.BooleanField()
	IsReplied = models.BooleanField()
	First = models.BooleanField()
	Second = models.BooleanField()
	IsSucceed = models.BooleanField()
	OnWatch = models.BooleanField()
	#Thoughts = models.TextField()
	class Meta:
		ordering = ('-OnWatch', '-IsApplied')
	def __unicode__(self):
		return self.CompanyName
    
class ApplicationAdmin(admin.ModelAdmin):
	list_display = (
					'__str__',
					#'CompanyName', 
					#'Contact', 
					'SubmitDate', 
					'OnWatch', 
					'IsApplied', 
					'IsReplied', 
					'First', 
					'Second', 
					'IsSucceed',
				)
	list_filter = (
					'OnWatch',
					'IsApplied', 
					'IsReplied',
					'SubmitDate',
				)
	actions = [
				'ChangeApplyStatue', 
				'ChangeApplyStatueFalse', 
				'ChangeReplyStatue', 
				'ChangeReplyStatueFalse',
				'ChangeSuccessStatue', 
				'ChangeSuccessStatueFalse', 
				'ChangeWatchStatue', 
				'ChangeWatchStatueFalse', 
				'ChangeFirstStatue', 
				'ChangeSecondStatue',
			]
	def ChangeApplyStatue(self, request, queryset):
		queryset.update(IsApplied=True)
	ChangeApplyStatue.short_description = "Applied"
	def ChangeApplyStatueFalse(self, request, queryset):
		queryset.update(IsApplied=False)
	ChangeApplyStatueFalse.short_description = "Not Applied"
	def ChangeReplyStatue(self, request, queryset):
		queryset.update(IsReplied=True)
	ChangeReplyStatue.short_description = "Replied"
	def ChangeReplyStatueFalse(self, request, queryset):
		queryset.update(IsReplied=False)
	ChangeReplyStatueFalse.short_description = "Not Replied"
	def ChangeSuccessStatue(self, request, queryset):
		queryset.update(IsSucceed=True)
	ChangeSuccessStatue.short_description = "Succeed"
	def ChangeSuccessStatueFalse(self, request, queryset):
		queryset.update(IsSucceed=False)
	ChangeSuccessStatueFalse.short_description = "Not Succeed"
	def ChangeWatchStatue(self,request, queryset):
		queryset.update(OnWatch=True)
	ChangeWatchStatue.short_description = "On Watch"
	def ChangeWatchStatueFalse(self,request, queryset):
		queryset.update(OnWatch=False)
	ChangeWatchStatueFalse.short_description = "Not On Watch"
	def ChangeFirstStatue(self, request, queryset):
		queryset.update(First = not True)
	ChangeFirstStatue.short_description = "Change First Statue"
	def ChangeSecondStatue(self, request, queryset):
		queryset.update(Second = not True)
	ChangeSecondStatue.short_description = "Change Second Statue"
	
class DailyReport(models.Model):
    Day = models.DateField()
    Done = models.TextField()
    Learnt = models.TextField()
    Thoughts = models.TextField()
    Plan = models.TextField() 
    class Meta:
        ordering = ['Day'] 
    def __unicode__(self):
        return str(self.Day)
 
class DailyReportAdmin(admin.ModelAdmin):
    list_display=('Day', 'Plan')

admin.site.register(Application, ApplicationAdmin)
admin.site.register(DailyReport, DailyReportAdmin)